package com.cxc.canal.listener;

import com.alibaba.otter.canal.protocol.CanalEntry;
import com.xpand.starter.canal.annotation.*;

@CanalEventListener
public class CanalDataEventListenerTest {


    /***
     * 增加数据监听
     * @param eventType
     * @param rowData
     */
//    @InsertListenPoint
    public void onEventInsert(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " ::   " + c.getValue()));
    }

    /***
     * 修改数据监听
     * @param rowData
     */

//    @UpdateListenPoint
    public void onEventUpdate(CanalEntry.RowData rowData){
        System.out.println("UpdateListenPoint");
        rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " ::   " + c.getValue()));
    }

    /***
     * 删除数据监听
     * @param eventType
     */
//    @DeleteListenPoint
    public void onEventDelete(CanalEntry.EventType eventType) {
        System.out.println("DeleteListenPoint");
    }

    /***
     * 自定义数据修改监听
     * @param eventType
     * @param rowData
     */
//    @ListenPoint(destination = "example", schema = "mrjtbaseservice_db", table = {"dwd_trd_process_domestic", "tb_user"}, eventType = CanalEntry.EventType.UPDATE)
    public void onEventCustomUpdate(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        System.err.println("onEventCustomUpdate");
        rowData.getAfterColumnsList().forEach((c) -> System.out.println("By--Annotation: " + c.getName() + " ::   " + c.getValue()));
    }


    /***
     * 自定义数据修改监听
     * @param eventType
     * @param rowData
     */
    @ListenPoint(destination = "example",
            schema = "dcresult",
            table = { "on_ads_deli_autosign"},
            eventType = {
                    CanalEntry.EventType.UPDATE,
                    CanalEntry.EventType.DELETE,
                    CanalEntry.EventType.INSERT})
    public void onEventCustomUpdateTest(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        System.out.println("eventType:=======>"+eventType);
        System.out.println("接收信息: " +rowData.toString());
//        rowData.getAfterColumnsList().forEach(
//                (c) -> System.out.println("接收信息: " + c.getName() + " ::   " + c.getValue())
//        );

    }

}
